package org.jeecg.modules.demo.mpwlwjc.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.demo.mpwlwjc.entity.ZwglMpsbsj;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 苗棚设备数据
 * @Author: jeecg-boot
 * @Date:   2023-04-17
 * @Version: V1.0
 */
@Mapper
public interface ZwglMpsbsjMapper extends BaseMapper<ZwglMpsbsj> {

    @Select("SELECT t1.* FROM zwgl_mpsbsj t1 " +
            "INNER JOIN (" +
            "    SELECT DATE(sj) AS date, MAX(id) AS max_id " +
            "    FROM zwgl_mpsbsj " +
            "    WHERE sj BETWEEN #{kaishishijian} AND #{jieshushijian} " +
            "    AND sbmc = #{sbmc} " +
            "    GROUP BY DATE(sj)" +
            ") t2 ON t1.id = t2.max_id")
    List<ZwglMpsbsj> selectByCondition(@Param("kaishishijian") String kaishishijian,
                                            @Param("jieshushijian") String jieshushijian,
                                            @Param("sbmc") String sbmc);


    @Select("SELECT sbmc, MAX(sj) AS sj, kqwd, kqsd,gz,eyhtnd,trwd,trsd " +
            "FROM zwgl_mpsbsj " +
            "WHERE sbmc = #{sbmc} " +
            "GROUP BY sbmc, DATE(sj), kqwd, kqsd,gz,eyhtnd,trwd,trsd " +
            "ORDER BY sj DESC " +
            "LIMIT 7")
    List<ZwglMpsbsj> getLatestDataForDevice(@Param("sbmc") String sbmc);

}
